package com.saturn.titan.core.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.saturn.titan.core.bean.PlatformEmp;
import com.saturn.titan.core.bean.PlatformRole;
import com.saturn.titan.core.repository.mybatis.PlatformEmpDao;
import com.saturn.titan.core.repository.mybatis.PlatformRoleDao;


/**
 * 用户管理类. 
 * 
 * @author lwh
 */
@Component
@Transactional(readOnly = true)
public class PlatformEmpService {

	public static final String HASH_ALGORITHM = "SHA-1";
	public static final int HASH_INTERATIONS = 1024;
	public static final int SALT_SIZE = 8;

	@Autowired
	private PlatformEmpDao platformEmpDao;
	
	@Autowired
	private PlatformRoleDao platformRoleDao;
	
	public PlatformEmp getEmp(Long id) {
		return platformEmpDao.selectById(id);
	}

	public PlatformEmp findEmpByLoginName(String loginName) {
		
		PlatformEmp emp = new PlatformEmp();
		emp.setAccount(loginName);
		
		List<PlatformEmp> result = platformEmpDao.select(emp);
		if(result.isEmpty()){
			return null;
		}
		return result.get(0);
	}

	public List<PlatformRole> findEmpRolesByEmpId(Long id) {
		
		return platformRoleDao.findRolesByEmpId(id);
	}
	
}
